﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using BLL.Entities.Client;

namespace HTAProDataImporter.Transport
{
    public class ClientInfoTransport : BaseEntityTransport
    {
         public override string CommandText
        {
            get { return "select * from tblClient"; }
        }

        public override void InstanceFromReader(OleDbDataReader DR)
        {
            ClientInfo client = ClientInfo.CreateNewInstance<ClientInfo>();
            client.CompanyID = DataStore.ActiveCompanyID;

            client.Contact.PhoneWork = DR["businessphone"].ToString();
            client.Contact.PhoneHome = DR["homephone"].ToString();
            client.Contact.PhoneMobile = DR["cell"].ToString();
            client.Contact.Fax = DR["fax"].ToString();
            client.Contact.Email = DR["email"].ToString();

            client.ContactMethod = DataStore.ContactMethodTypeValues[DR["fkContactMethod"].ToString()];
            client.Gender = DR["fkGenderID"].ToString() == "1" ? DataStore.GenderType.Values["Male"] : DataStore.GenderType.Values["Female"];

            DateTime di = DateTime.MinValue;
            DateTime.TryParse(DR["IntakeDate"].ToString(), out di);
            client.DateObtained = di;

            client.License.LicenseNumber = DR["DriversLicence"].ToString();

            DateTime br = DateTime.MinValue;
            DateTime.TryParse(DR["Birthday"].ToString(), out br);
            client.Birthday = br;

            client.Notes = DR["Notes"].ToString();

            DataStore.Clients.Add(DR["pkClientID"].ToString(), client);
        }
    }
}
